/**
 * 
 * @authors supmain (mtingfeng@gmail.com)
 * @date    2014-08-13 10:16:10
 * @update  2014-08-13 10:16:10
 * @for webapp.html
 * @version $Id$
 */
var BST = BST || {};
BST.joinus = {
    init:function(){
        var that = this;
        /*检测用户是否申请过代理商*/
        that.checkIsApply();
    },
    nTabs:function(thisObj,Num){
        if(thisObj.className == "on")return;
        var tabObj = thisObj.parentNode.id;
        var tabList = document.getElementById(tabObj).getElementsByTagName("li");
        for(i=0; i <tabList.length; i++) {
            if (Num == 1) {
                $("#imgPage").hide();
            } else {
                $("#imgPage").show();
            }
          
          if (i == Num)
          {
           thisObj.className = "active"; 
              document.getElementById(tabObj+"_Content"+i).style.display = "block";
          }else{
           tabList[i].className = "sta"; 
           document.getElementById(tabObj+"_Content"+i).style.display = "none";
          }
        }
    },
    /*检测用户是否申请过代理商*/
    checkIsApply : function() {
    	$('.sq_btn').on('click',function(event){
    		var requestURI = $('#returnUrl').val(),
    			applyType = $('#applyType').val();
    		$.ajax({
				type : "POST",
				url : "/common/checkLogin",
				async : false,
				dataType: 'json',
				success:function(data) {
					if(data) {
						$.ajax({
							type : "POST",
							url : "/partner/checkIsApply",
							async : false,
							dataType: 'json',
							success:function(data) {
								if(data.isApply) {
									BSTYUN.dialog.warn(data.warn);
								}else {
									location.href="/partner/apply?applyType="+applyType;
								}
							}
						})
					}else {
						location.href = "/user/login?returnUrl="+requestURI;
					}
				}
			})
    	})
    }
};
$(function(){
    BST.joinus.init();
});

function DrawImage(ImgD,iwidth,iheight){
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){
        flag=true;
        if(image.width/image.height>= iwidth/iheight){
            if(image.width>iwidth){ 
                ImgD.width=iwidth;
                ImgD.height=(image.height*iwidth)/image.width;
            }else{
                ImgD.width=image.width; 
                ImgD.height=image.height;
            }
        }else{
            if(image.height>iheight){ 
                ImgD.height=iheight;
                ImgD.width=(image.width*iheight)/image.height; 
            }else{
                ImgD.width=image.width; 
                ImgD.height=image.height;
            }
        }
    }
}  

